<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>回调</title>

    <!--引入vue + axios-->
    <script src="js/plugins/vue/dist/vue.js"></script>
    <script src="js/plugins/axios/dist/axios.js"></script>
    <!--全局使用-->
    <script src="js/common.js"></script>
</head>
<body>
<div id="myDiv">

</div>

</body>
<script type="text/javascript">
    new Vue({
        el:"#myDiv",
        mounted(){
            //1.解析参数
            let url = location.href;
            let paramObj = parseUrlParams2Obj(url);
            //2.发送axios请求 微信登录接口
            console.log(paramObj.code)
            this.$http.post("/login/wechat",{"code":paramObj.code})
                .then(result=>{
                    result = result.data;//AjaxResult
                    if(result.success){//说明是第2---n次扫码，直接登录成功
                        localStorage.setItem("token",result.resultobj.token);//UUID的随机串
                        //注意：需要将返回的JSON对象转换成JSON字符串存储
                        localStorage.setItem("logininfo",JSON.stringify(result.resultobj.logininfo));
                        //登录成功，跳转到首页
                        location.href = "index.html";
                    }else{//跳转到绑定页面
                        let binderUrl = "binder.html"+result.resultobj;
                        location.href = binderUrl;
                    }
                })
                .catch(result=>{
                    alert("进不去哦！！！")
                })
        }
    })
</script>
</html>